package com.feinno.urcs.group.pc.task;

import com.feinno.rpc.channel.RpcFuture;
import com.feinno.rpc.client.RpcMethodStub;
import com.feinno.urcs.group.pctask.task.AndPcDismissGroupNotifyArgs;
import com.feinno.urcs.group.siptask.task.GroupTaskEvents;
import org.helium.framework.annotations.FieldSetter;
import org.helium.framework.annotations.TaskImplementation;
import org.helium.framework.rpc.LegacyRpcClient;
import org.helium.framework.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by honghao on 7/20/15.
 */
@TaskImplementation(event = GroupTaskEvents.DISMISS_GROUP_NOTIFY_TO_PC)
public class AndPcDismissGroupNotifyTask implements Task<AndPcDismissGroupNotifyArgs> {

	private Logger LOGGER = LoggerFactory.getLogger(AndPcDismissGroupNotifyTask.class);

	@FieldSetter("${PC_SERVER_RPC_SERVICE}")
	private LegacyRpcClient pcServerRpcClient;
	private String rpcMethodName = "GroupChatOver";

	@Override
	public void processTask(AndPcDismissGroupNotifyArgs args) {
		try {
			LOGGER.info("invoke GroupChatOver, args :{}", args.toString());
			RpcMethodStub stub = pcServerRpcClient.getMethodStub(rpcMethodName);
			RpcFuture future = stub.invoke(args);
			future.addListener(ret -> {
				if (ret.getError() != null) {
					LOGGER.error("AndPcDismissGroupNotifyTask occur error : {}", ret.getError());
				}
			});
		} catch (Exception ex) {
			LOGGER.error("invoke GroupChatOver occur error : {}", ex);
		}
	}
}
